<template>
	<view>
		<view >
			<image :src="img_src" @click="preview" style="background-size: contain; width: 100%; height: 900rpx;"></image>
		</view>
		
		<view class="show-buttons" style="display: flex;">
			<button @click="accept(1)">同意</button>
			<button @click="accept(0)">拒绝</button>
		</view>
	</view>
</template>


<script>
	export default {
		onLoad(option){
			this.option = option;
			console.log(option);
			this.init();
		},
		data() {
			return {
				option: null,
				img_src: '',
			}
		},
		methods: {
			isArrayFn (o) {
				if (o == undefined)
				return false
				
				return Object.prototype.toString.call(o) === '[object Array]';
			},
			previewImages(urls, index) {
						// 预览图片
						// - 用法: previewImages(url)或者previewImages(urls, index)
						if (index == undefined) 	index = 0;
						if (!this.isArrayFn(urls)) urls = [urls];
			
						uni.previewImage({
							urls: urls,
							current: index,
							indicator: 'default',
							longPressActions: {
								itemList: ['发送给朋友', '保存图片', '收藏'],
								success: function(data) {
									console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
								},
								fail: function(err) {
									console.log(err.errMsg);
								}
							}
					  	});
			},
			preview() {
				this.previewImages(this.img_src);
			},
			init(){
				var key = this.option.key;
				var kk = key.substring(0, 1);
				this.img_src = this.api.baseUrl + '/api/template/doc/images/' + kk + '.png'
			},
			accept(v) {
				/* 返回调用页面并把图片URL传递过去 */
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2]; 
				let key = this.option.key;
				var dc = {[key]: v};
				console.log('dc ~~~~~~~ ', dc);
				prevPage.setData(dc);
				
				uni.navigateBack();
				
			}
		},
	}
	
</script>

<style>
</style>
